package com.atguigu.mediator2;

import java.util.ArrayList;
import java.util.List;

/**
 * 具体中介者
 */
public class MediatorExt extends Mediator {
	
	/** 同事类集合 */
	private List<Colleague> colleagueList = new ArrayList<Colleague>();

	/**
	 * 注册
	 */
	public void register(Colleague colleague) {
		if (!colleagueList.contains(colleague)) {
			colleagueList.add(colleague);
			colleague.setMediator(this);
		}
	}

	/**
	 * 转发 —— 让其他同事转换消息（自己除外）
	 */
	public void relay(Colleague cl) {
		
		for (Colleague ob : colleagueList) {
			// 自己除外
			if (!ob.equals(cl)) {
				ob.receive(cl.getMsg());
				//((Colleague) ob).receive(cl.getMsg());
			}
		}
	}
}